package org.beetl.json;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.beetl.json.annotation.Json;
import org.beetl.json.annotation.JsonPolicy;

public class Test {

	public static void main(String[] args)throws IOException {
		{
			JsonTool tool = new JsonTool();
			
			{
//				String policy= "~c:?null->[],~f:f/#.##/";
//				List<Location> list = JsonTool.parseStringPolicy(policy);
//				for(Location loc:list){
//					System.out.println(loc.getClass());
//				}
			}
			
			tool.addLocationAction("~d","f/yyyy.MM.dd/");	
			tool.addPolicy("~f:f/#.##/,~c:?null->[]");
	
			tool.addLocationAction("~L/java.util.Calendar*/","$.getTime->f/yyyy-MM-dd/");
			
			tool.pretty = false;
			
			{
					
//				User user = new User();	
//				Product p = new Product();
//				p.setUser(user);
//				Customer customer = new Customer(p);
//				user.setCustomer(customer);
//				p.setCustomer(customer);
//				
//				String jsonString = tool.serialize(user);			
////				System.out.println("ojbString="+ojbString);
//				System.out.println("jsonString="+jsonString);
			}
			
	
			{
//				Map map = new HashMap();
////				map.put("date",Calendar.getInstance());
//				map.put("age",1);
//				map.put("array", new Object[]{1,2,"abc"});
//				map.put("name","joelli");
////				
//				String json = tool.serialize(map,"[array][0]:i");
//				System.out.println("jsonString="+json);
			}
			
			{
//				List list = new ArrayList();
//				list.add(0);
//				list.add(1);
//				list.add(new Foo());
//				String json = tool.serialize(list,"[0]:i","~L/org.beetl.json.Foo/:i");
//				System.out.println("jsonString="+json);
			}
//			
			{
//				String jsonString = JsonTool.serialize(new Foo());
//				System.out.println("jsonString="+jsonString);
			}
			
		
			
		
		}
	}	

}

class Foo{
	int id =1;
	String age = "12";
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getAge() {
		return age;
	}
	public void setAge(String age) {
		this.age = age;
	}
	
	
}

class User{	
	int id = 1;
	Customer  customer  = null;	
	public User(){
		
	}
	
	
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
}

class Customer{
	String name="lijz1";	
	Product product = null;
	public Customer(Product product){
		this.product = product;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Product getProduct() {
		return product;
	}
	public void setProduct(Product product) {
		this.product = product;
	}
	
	
	
}

class Product{
	String name = "p";
	User user = null;
	Customer customer;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
}
